package com.cnhis.drgs.common;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import com.alibaba.fastjson.annotation.JSONField;
import com.cnhis.drgs.util.Util;
import com.cnhis.drgs.vo.Page;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Response implements Serializable {
    private int code;
    private String msg;
    private Object data;

    public Response() {
    }

    public Response(int code) {
        this(code, (String)null);
    }

    public Response(int code, String msg) {
        this(code, msg, (Object)null);
    }

    public Response(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Response createSuccess() {
        return createSuccess((String)null);
    }

    public static Response createSuccess(String msg) {
        return createSuccess(msg, (Object)null);
    }

    public static Response createSuccess(Page page) {
        Map<String, Object> map = new HashMap();
        map.put("pageNo", page.getPageNo());
        map.put("pageNum", page.getPageNum());
        map.put("pageSize", page.getPageSize());
        map.put("rowCount", page.getRowCount());
        Map<String, Object> data = new HashMap();
        data.put("page", map);
        data.put("items", page.getList());
        return createSuccess((String)null, data);
    }

    public static Response createSuccess(Object data) {
        return createSuccess((String)null, data);
    }

    public static Response createSuccess(String msg, Object data) {
        return new Response(ResponseCode.Common.SUCCESS.getCode(), StringUtils.isBlank(msg) ? ResponseCode.Common.SUCCESS.getMsg() : msg, data);
    }

    public static Response createFail() {
        return createFail((ResponseCode) ResponseCode.Common.ERROR);
    }

    public static Response createFail(ResponseCode responseCode) {
        return createFail(responseCode, (Object)null);
    }

    public static Response createFail(ResponseCode responseCode, Map<String, Object> params) {
        return createFail(responseCode, params, (Object)null);
    }

    public static Response createFail(String msg) {
        return new Response(ResponseCode.Common.ERROR.getCode(), msg);
    }

    public static Response createFail(ResponseCode responseCode, Object data) {
        return createFail(responseCode, (Map)null, data);
    }

    public static Response createFail(ResponseCode responseCode, Map<String, Object> params, Object data) {
        return new Response(responseCode.getCode(), Util.fillTemplateMessage(responseCode.getMsg(), params), data);
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @JSONField(
            serialize = false
    )
    public boolean isSuccess() {
        return this.code == ResponseCode.Common.SUCCESS.getCode();
    }

    public String toString() {
        return "Response{code=" + this.code + ", msg='" + this.msg + '\'' + ", data=" + this.data + '}';
    }
}

